import React from 'react'

let { Provider, Consumer: CountConsumer } = React.createContext();


class CountProvider extends React.Component {

  constructor() {
    super();
    this.state = {
      num: 100
    }
  }

  increment = () => {
    this.setState({
      num: this.state.num + 1
    })
  }

  decrement(){
    this.setState({
      num: this.state.num - 1
    })
  }

  render() {
    return (
      <Provider value={{
        num: this.state.num,
        inc: this.increment,
        dec: this.decrement.bind(this)
      }}>
        {this.props.children}
      </Provider>
    )
  }

}

export  {
  CountProvider,
  CountConsumer
}